/*
Illuminator (LED drawing tool for iPhone)
Copyright (C) 2008
Nik S Denin
Ivan A Vlasov
Dmitriy A Jackovlev

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _DRAWFIELD_H
#define _DRAWFIELD_H

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <GraphicsServices/GraphicsServices.h>

#import "GlobalDefinitions.h"

#import "ILTopToolbar.h"
#import "ILBottomToolbar.h"

/* lamp size without glow */
#define LAMPDIM 10.0
/* lamp size with glow */
#define LAMPLIGHT 21.0

/* maximum undo size */
#define MAX_UNDO 10

typedef enum
{
	DFEnabled = 0,
	DFDisabled = 1,
} DFFieldState;

typedef enum
{
	DFFilling = 0,
	DFErasing = 1
} DFFillingState;

@interface DrawField : UIView
{
	UIImage *m_lamp; ///< Image of one lamp
	CGPoint m_gridPoints[(int)(320.0 / LAMPDIM)][(int)(480.0 / LAMPDIM)]; ///< Grid of points (depends on lamp size)
	UIImageView *m_lampViews[(int)(320.0 / LAMPDIM)][(int)(480.0 / LAMPDIM)]; ///< array of lamp views (depends on lamp size)
	BOOL m_thisSession[(int)(320.0 / LAMPDIM)][(int)(480.0 / LAMPDIM)]; ///< Flag that shows that this lamp was drawn in this session (this session until mouse up)
	id m_delegate; ///< delegate for changing views

	ILTopToolbar *m_topToolbar; ///< Top toolbar
	ILBottomToolbar *m_bottomToolbar; ///< Bottom toolbar

	BOOL m_fieldState;
	BOOL m_fillingState;

	int m_undoCounter;
	NSMutableArray *m_undoArray;
}

- (id)initWithFrame:(CGRect)frame;
- (void)showToolbars;
- (void)hideToolbars;
- (void)constructGrid;
- (void)workingWithRect:(CGRect)lampRect withPoint:(CGPoint)point;

/* top toolbar methods */
- (void)setSmallField;
- (void)setMediumField;
- (void)setLargeField;
- (void)invertImage;
- (void)setFill:(short)state;

- (short)getFillingState;

- (void)undo;
- (void)redo;

/* bottom toolbar methods */
- (void)newImage;
- (void)saveImage;
- (void)showList;
- (void)mailImage;
- (void)bomb;

- (void)setDelegate:(id)delegate;
- (void)dealloc;


- (void)slideUp;

@end // DrawField

#endif // _DRAWFIELD_H
